//
//  UINavigationController+HKLeak.m
//  HKUtilities
//
//  Created by 胡锦涛 on 2020/4/5.
//  Copyright © 2020 胡锦涛. All rights reserved.
//

#import "UINavigationController+HKLeak.h"
#import "UIViewController+HKLeak.h"
#import "UIViewController+HKExtension.h"
@implementation UINavigationController (HKLeak)
+(void)load{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{///交换时机方法pop
        [self hk_changeSel:@selector(popViewControllerAnimated:) toSel:@selector(leak_popViewControllerAnimated:)];
        [self hk_changeSel:@selector(popToViewController:animated:) toSel:@selector(leak_popToViewController:animated:)];
        [self hk_changeSel: @selector(popToRootViewControllerAnimated:) toSel:@selector(leak_popToRootViewControllerAnimated:)];
    });
}
///pop 设置标识
-(UIViewController *)leak_popViewControllerAnimated:(BOOL)animated{
    
    UIViewController* viewController = [self leak_popViewControllerAnimated:animated];
    viewController.isHKDisappear = YES;
    return viewController;
}
/// 拿到被pop的viewControllers，依次调用延时任务
-(NSArray<UIViewController *> *)leak_popToRootViewControllerAnimated:(BOOL)animated{
    
    NSArray<UIViewController *> * viewControllers = [self leak_popToRootViewControllerAnimated:animated];
    for (UIViewController* vc in viewControllers) {
        [vc willDealloc];
    }
    return viewControllers;
}
/// 拿到被pop的viewControllers，依次调用延时任务
-(NSArray<UIViewController *> *)leak_popToViewController:(UIViewController *)viewController animated:(BOOL)animated{
    NSArray<UIViewController *> * viewControllers = [self leak_popToViewController:viewController animated:animated];
    for (UIViewController* vc in viewControllers) {
        [vc willDealloc];
    }
    return viewControllers;
}
@end
